//主要实现语音识别子服务的服务器的搭建
#include "friend_server.hpp"


DEFINE_bool(run_mode, false, "程序的运行模式, false-调试; true-发布;");
DEFINE_string(log_file, "", "发布模式下, 用于指定日志的输出文件");
DEFINE_int32(log_level, 0, "发布模式下, 用于指定日志输出等级");  //trace default 0
//服务注册
DEFINE_string(etcd_registry_host, "http://127.0.0.1:2379", "这是服务中心地址");
DEFINE_string(etcd_instance_name, "/friend_service/instance", "当前服务实例在注册中心中的唯一标识"); //FLAGS_base_service + FLAGS_etcd_instance_name 注册地址
DEFINE_string(etcd_access_host, "127.0.0.1:10006", "当前服务实例对外提供服务的访问地址");

DEFINE_int32(rpc_listen_port, 10006, "Rpc服务器监听端口");
DEFINE_int32(rpc_timeout, -1, "Rpc服务器空闲超时时间 ");  
DEFINE_int32(rpc_threads, 1, "Rpc服务器的工作线程数"); 
//服务发现
DEFINE_string(base_service, "/service", "服务监控根目录");
DEFINE_string(message_service, "/service/message_service", "消息存储子服务服务名称");
DEFINE_string(user_service, "/service/user_service", "用户管理子服务服务名称");

DEFINE_string(es_host, "http://127.0.0.1:9200/", "ES搜索引URL"); // 千万别少了最后的/

DEFINE_string(mysql_user, "root", "mqsql访问用户");
DEFINE_string(mysql_password, "299274142", "mqsql访问密码");
DEFINE_string(mysql_host, "127.0.0.1", "mqsql服务器访问地址");
DEFINE_string(mysql_database, "xchat", "mqsql数据库名称");
DEFINE_string(mysql_cset, "utf8", "mqsql客户端字符集");
DEFINE_int32(mysql_port, 0, "mysql服务器访问端口");
DEFINE_int32(mysql_pool_count, 4, "mysql连接池大小");


int main(int argc, char* argv[])
{
    google::ParseCommandLineFlags(&argc, &argv, true);
    
    xchat::init_logger(FLAGS_run_mode, FLAGS_log_file, FLAGS_log_level);

    xchat::FriendServerBuilder fdsb;
    fdsb.make_es_object({FLAGS_es_host});
    fdsb.make_mysql_object(FLAGS_mysql_user, FLAGS_mysql_password, FLAGS_mysql_host, FLAGS_mysql_database, FLAGS_mysql_cset, FLAGS_mysql_port, FLAGS_mysql_pool_count);
    fdsb.make_discovery_object(FLAGS_etcd_registry_host, FLAGS_base_service, FLAGS_user_service, FLAGS_message_service); //最后一个参数是需要关心哪一个
    fdsb.make_rpc_server(FLAGS_rpc_listen_port, FLAGS_rpc_timeout, FLAGS_rpc_threads);
    fdsb.make_registry_object(FLAGS_etcd_registry_host, FLAGS_base_service + FLAGS_etcd_instance_name, FLAGS_etcd_access_host);

    auto server = fdsb.build();
    server->start();
    return 0;
}